package com.atguigu.algorithm;

public class Hanoi {
    public static void main(String[] args) {
        Hanoi honoi=new Hanoi();
        honoi.hanota(5);
    }

    public void hanota(int n){
        if(n>0){
            func(n,"左","中","右");
        }
    }

    public void func(int i,String start,String other,String end){
        if(i==1){
            System.out.println("把"+i+"从"+start+"移到"+end);
        }else{
            //把i-1层移动到other
            func(i-1,start,end,other);
            //把第i层移动到end
            System.out.println("把"+i+"从"+start+"移到"+end);
            //把other的i-1移到end
            func(i-1,other,start,end);
        }
    }
}
